package com.stylefeng.guns.rest.modular.App.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.model.CommonKeyValue;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.rest.modular.App.dao.DriverRefuseTaskMapper;
import com.stylefeng.guns.rest.modular.App.model.DriverRefuseTask;
import com.stylefeng.guns.rest.modular.App.service.IDriverRefuseTaskService;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**

 * 驾驶员拒单登记信息 Service 实现 
 * @author sasazaixian
 * @Date 2018-11-16 11:33
 */
@Service
public class DriverRefuseTaskServiceImpl extends ServiceImpl<DriverRefuseTaskMapper,DriverRefuseTask> implements IDriverRefuseTaskService {

    @Resource
    private DriverRefuseTaskMapper driverRefuseTaskMapper;

    /**
     * 删除驾驶员拒单登记信息
     * @param driverRefuseTask
     * @return     
     */
    @Transactional
    public int deleteDriverRefuseTask(DriverRefuseTask driverRefuseTask,String token)throws Exception{
        if(driverRefuseTask==null ){
            throw new RuntimeException("参数不全！");
        }
        return this.driverRefuseTaskMapper.deleteDriverRefuseTask(driverRefuseTask);
    }
    /**
     * 批量删除驾驶员拒单登记信息
     * @param ids 主键ID数组
     * @return 
     */
    @Transactional
    public int deleteBatchDriverRefuseTask(String[] ids,String token)throws Exception{
        return this.driverRefuseTaskMapper.deleteBatchDriverRefuseTask(ids);
    }
    /**
     * 查询驾驶员拒单登记信息列表
     * @param driverRefuseTask 驾驶员拒单登记信息对象
     * @return
     */
    public List<DriverRefuseTask> selectListDriverRefuseTask(DriverRefuseTask driverRefuseTask,String token)throws Exception{
        return  this.driverRefuseTaskMapper.selectListDriverRefuseTask(driverRefuseTask);
    }
    /**
	 * 分页查询驾驶员拒单登记信息列表
     * @param pager 分页对象
     * @return
     */     
    public  Map pageListDriverRefuseTask(Pager pager,String token) throws Exception{
        Page page=new Page(pager.getPageNumber(),pager.getPageSize());
        page.setRecords(driverRefuseTaskMapper.selectListDriverRefuseTask(page,(DriverRefuseTask)pager.getObj()));
        List<DriverRefuseTask> list = page.getRecords();
        Map mapDate = new HashMap();
        mapDate.put("rows", list);
        mapDate.put("total", page.getTotal());
        mapDate.put("page", page.getCurrent());
        mapDate.put("pageCount", page.getPages());
        return mapDate;
    }
    /**
     * 同一个事务 互斥锁查询
     * @param driverRefuseTask 驾驶员拒单登记信息对象
     * @return 
     */
    public  List<DriverRefuseTask> selectListDriverRefuseTaskForUpdate(DriverRefuseTask driverRefuseTask)throws Exception{
        return  this.driverRefuseTaskMapper.selectListDriverRefuseTaskForUpdate(driverRefuseTask);
    }
    /**
     * 通过主键id查询的驾驶员拒单登记信息列表
     * @param id 主键id
     * @return     
     */
    public  DriverRefuseTask findDriverRefuseTaskById(String id,String token)throws Exception{
        return  this.driverRefuseTaskMapper.findDriverRefuseTaskById(id);
    }

    /**
     * 新增驾驶员拒单登记信息数据
     * @param driverRefuseTask  驾驶员拒单登记信息对象
     * @return
     */
    @Transactional
    public int insertDriverRefuseTask(DriverRefuseTask driverRefuseTask,String token) throws Exception { 
        if(driverRefuseTask!=null && (driverRefuseTask.getDrtId()==null || driverRefuseTask.getDrtId().trim().length()<10)){
            driverRefuseTask.setDrtId(IdWorker.get32UUID());
        }  
        return this.driverRefuseTaskMapper.insertDriverRefuseTask(driverRefuseTask);
    }
    
    /**
     * 更新驾驶员拒单登记信息数据
     * @param driverRefuseTask 驾驶员拒单登记信息对象
     * @return     
     */
    @Transactional
    public int updateDriverRefuseTask(DriverRefuseTask driverRefuseTask,String token) throws Exception {     	
        return  this.driverRefuseTaskMapper.updateDriverRefuseTask(driverRefuseTask);
    }    
    /**
     * 查询驾驶员拒单登记信息返回key-Value属性
     * @param driverRefuseTask 系统操作对象
     * @return     
     */
    public List<CommonKeyValue> optionsDriverRefuseTask(DriverRefuseTask driverRefuseTask,String token) throws Exception {
        List<DriverRefuseTask> listDriverRefuseTask=this.driverRefuseTaskMapper.selectListDriverRefuseTask(driverRefuseTask);
        List<CommonKeyValue> listOptions=new ArrayList<CommonKeyValue>();
        for(DriverRefuseTask item:listDriverRefuseTask){
            CommonKeyValue opts=new CommonKeyValue();
            opts.setId(""+item.getDrtId());
            opts.setValue(item.getDrtId());
            listOptions.add(opts);
        }
        return listOptions;
    }
}
